/*
 * Copyright (c) csii.com.cn 2016 zhaojin
 */

package com.csii.ssm.controller.tianhong;

import com.csii.ssm.common.Dict;
import com.csii.ssm.core.CommonDict;
import com.csii.ssm.dto.AjaxData;
import com.csii.ssm.exception.AccessRuntimeException;
import com.csii.ssm.exception.AccessRuntimeExceptionDict;
import com.csii.ssm.service.IPjnlService;
import com.csii.ssm.service.IUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.context.ServletContextAware;

import javax.inject.Inject;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 天虹支付账户管理类控制器
 *
 * @author Charis
 * @create 2016-08-12-08:59
 */
@Controller
public class AcmgmtController extends ThBaseController implements ServletContextAware {

    private static final Logger logger = LoggerFactory.getLogger(AcmgmtController.class);

    @Inject
    private IUserService userService;

    @Inject
    private IPjnlService pjnlService;

    /**
     * 响应支付功能开通
     * @param pin_data 支付密码
     * @param model
     * @param httpSession
     */
    @RequestMapping(value = Dict.TRS_OPENPAYFUNCONFIRM, method = RequestMethod.POST)
    public void openPayFunConfirm(@RequestParam(required = true) String resToken,@RequestParam String pin_data, Model model, HttpSession httpSession) {
        try {
            //todo  	响应支付功能开通
            //User user = (User) httpSession.getAttribute(Dict.LOGINUSER);
            //logger.debug(user.getTel());
            logger.debug("resToken=="+resToken);
            AjaxData ajaxData = getAjaxData();
            Map data= new HashMap();
            data.put("txn_id",headFormatter.getTxnMaping().get( Dict.TRS_OPENPAYFUNCONFIRM));
            data.put("chnl","152123");
            data.put("accno","15212345");
            data.put("systrace","152000");
            data.put("rc","1");
            data.put("rc_detail","返回码解释:支付功能开通");
            data.put("acq_id","15200");
            data.put("org_code","152152");
            data.put("teller","152");
            data.put("txn_date","2016-8-29");
            data.put("txn_time","14:21");
            ajaxData.setDataMap(data);
            model.addAttribute(CommonDict.RES,ajaxData);
        } catch (AccessRuntimeException e) {
            throw new AccessRuntimeException(e.getMessage(), e);
        } catch (Exception e) {
            e.printStackTrace();
            throw new AccessRuntimeException(AccessRuntimeExceptionDict.ERROR_OPENPAYFUNCONFIRM);
        }
    }

    /**
     * 支付功能开通查询请求
     * @param model
     * @param httpSession
     */
    @RequestMapping(value = Dict.TRS_OPENPAYFUNQRY, method = RequestMethod.GET)
    public void openPayFunQry( Model model, HttpSession httpSession) {
        try {
            //todo  	响应支付功能开通查询
            //User user = (User) httpSession.getAttribute(Dict.LOGINUSER);
            //logger.debug(user.getTel());
            AjaxData ajaxData = getAjaxData();
            Map data = new HashMap();
            data.put("txn_id",headFormatter.getTxnMaping().get(Dict.TRS_OPENPAYFUNQRY));
            data.put("chnl","152123");
            data.put("accno","152135338");
            data.put("systrace","152123");
            data.put("rc","152122");
            data.put("rc_detail","返回码解释:支付功能开通查询");
            data.put("acq_id","012345");
            data.put("org_code","12345");
            data.put("status","1");
            data.put("teller","code123");
            data.put("txn_date","2016-8-29");
            data.put("txn_time","13:15");
            ajaxData.setDataMap(data);
            model.addAttribute(CommonDict.RES,ajaxData);
        } catch (AccessRuntimeException e) {
            throw new AccessRuntimeException(e.getMessage(), e);
        } catch (Exception e) {
            e.printStackTrace();
            throw new AccessRuntimeException(AccessRuntimeExceptionDict.ERROR_OPENPAYFUNQRY);
        }
    }
    /**
     *打开支付功能响应
     * @param pin_data 支付密码
     * @param model
     * @param httpSession
     */
    @RequestMapping(value = Dict.TRS_OPENPAYCONFIRM, method = RequestMethod.POST)
    public void openPayConfirm(@RequestParam(required=true) String resToken,@RequestParam String pin_data,
                               @RequestParam String sms_code, Model model, HttpSession httpSession) {
        try {
            //todo  	打开支付功能
            //User user = (User) httpSession.getAttribute(Dict.LOGINUSER);
            //logger.debug(user.getTel());
            AjaxData ajaxData = getAjaxData();
            Map data = new HashMap();
            data.put("txn_id",headFormatter.getTxnMaping().get(Dict.TRS_OPENPAYCONFIRM));
            data.put("chnl","154");
            data.put("accno","154111");
            data.put("pin_retry","1");
            data.put("systrace","161123");
            data.put("rc","161122");
            data.put("rc_detail","返回码解释:打开支付功能");
            data.put("acq_id","012345");
            data.put("org_code","12345");
            data.put("teller","code123");
            data.put("txn_date","2016-8-29");
            ajaxData.setDataMap(data);
            model.addAttribute(CommonDict.RES,ajaxData);
        } catch (AccessRuntimeException e) {
            throw new AccessRuntimeException(e.getMessage(), e);
        } catch (Exception e) {
            e.printStackTrace();
            throw new AccessRuntimeException(AccessRuntimeExceptionDict.ERROR_OPENPAYCONFIRM);
        }
    }

    /**
     * 关闭支付功能响应
     * @param pin_data 支付密码
     * @param model
     * @param httpSession
     */
    @RequestMapping(value = Dict.TRS_CLOSEPAYCONFIRM, method = RequestMethod.POST)
    public void closePayConfirm(@RequestParam(required=true) String resToken,@RequestParam String pin_data,
                                @RequestParam String sms_code, Model model, HttpSession httpSession) {
        try {
            //todo  	关闭支付功能
           // User user = (User) httpSession.getAttribute(Dict.LOGINUSER);
            //logger.debug(user.getTel());
            AjaxData ajaxData = getAjaxData();
            Map data = new HashMap();
            data.put("txn_id",headFormatter.getTxnMaping().get(Dict.TRS_CLOSEPAYCONFIRM));
            data.put("chnl","153");
            data.put("accno","153111");
            data.put("pin_retry","1");
            data.put("systrace","161123");
            data.put("rc","161122");
            data.put("rc_detail","返回码解释:关闭支付功能");
            data.put("acq_id","012345");
            data.put("org_code","12345");
            data.put("teller","code123");
            data.put("txn_date","2016-8-29");
            ajaxData.setDataMap(data);
            model.addAttribute(CommonDict.RES,ajaxData);
        } catch (AccessRuntimeException e) {
            throw new AccessRuntimeException(e.getMessage(), e);
        } catch (Exception e) {
            e.printStackTrace();
            throw new AccessRuntimeException(AccessRuntimeExceptionDict.ERROR_CLOSEPAYCONFIRM);
        }
    }

    /**
     * 绑定储值卡响应
     * @param pin_data 所需绑定的覆膜储值卡密码
     * @param pan 储值卡卡号
     * @param model
     * @param httpSession
     */
    @RequestMapping(value = Dict.TRS_BINDCARDCONFIRM, method = RequestMethod.POST)
    public void bindCardConfirm(@RequestParam(required=true) String resToken,@RequestParam String pin_data,@RequestParam String pan, Model model, HttpSession httpSession) {
        try {
            //todo  	绑定储值卡
           // User user = (User) httpSession.getAttribute(Dict.LOGINUSER);
            //logger.debug(user.getTel());
            AjaxData ajaxData = getAjaxData();
            Map data = new HashMap();
            data.put("txn_id",headFormatter.getTxnMaping().get(Dict.TRS_BINDCARDCONFIRM));
            data.put("chnl","156");
            data.put("accno","156111");
            data.put("systrace","156123");
            data.put("rc","156122");
            data.put("rc_detail","返回码解释:绑定储值卡");
            data.put("acq_id","012345");
            data.put("org_code","12345");
            data.put("teller","code123");
            data.put("txn_date","2016-8-29");
            data.put("txn_time",new Date());
            ajaxData.setDataMap(data);
            model.addAttribute(CommonDict.RES,ajaxData);
        } catch (AccessRuntimeException e) {
            throw new AccessRuntimeException(e.getMessage(), e);
        } catch (Exception e) {
            e.printStackTrace();
            throw new AccessRuntimeException(AccessRuntimeExceptionDict.ERROR_BINDCARDCONFIRM);
        }
    }

    /**
     * 解除绑定储值卡响应
     * @param pin_data 支付密码
     * @param pan 储值卡卡号
     * @param model
     * @param httpSession
     */
    @RequestMapping(value = Dict.TRS_UNBINDCARDCONFIRM, method = RequestMethod.POST)
    public void unbindCardConfirm(@RequestParam(required=true) String resToken,@RequestParam String pin_data,@RequestParam String pan, Model model, HttpSession httpSession) {
        try {
            //todo  	解除绑定储值卡
            // User user = (User) httpSession.getAttribute(Dict.LOGINUSER);
            //logger.debug(user.getTel());
            AjaxData ajaxData = getAjaxData();
            Map data = new HashMap();
            data.put("txn_id",headFormatter.getTxnMaping().get(Dict.TRS_UNBINDCARDCONFIRM));
            data.put("chnl","157");
            data.put("accno","157111");
            data.put("pin_retry","3");
            data.put("systrace","157123");
            data.put("rc","157122");
            data.put("rc_detail","返回码解释:解除绑定储值卡");
            data.put("acq_id","012345");
            data.put("org_code","12345");
            data.put("teller","code123");
            data.put("txn_date","2016-8-29");
            data.put("txn_time",new Date());
            ajaxData.setDataMap(data);
            model.addAttribute(CommonDict.RES,ajaxData);
        } catch (AccessRuntimeException e) {
            throw new AccessRuntimeException(e.getMessage(), e);
        } catch (Exception e) {
            e.printStackTrace();
            throw new AccessRuntimeException(AccessRuntimeExceptionDict.ERROR_UNBINDCARDCONFIRM);
        }
    }


    /**
     * 支付账户修改响应
     * @param pin_data 支付密码
     * @param pay_hwm 单笔支付限额
     * @param day_hwm 单日累计支付限额
     * @param pf_hwm 单笔免密限额
     * @param pf_day_hwm 单日免密限额
     * @param model
     * @param httpSession
     */
    @RequestMapping(value = Dict.TRS_MODIFYPAYFUNCONFIRM, method = RequestMethod.POST)
    public void modifyPayFunConfirm(@RequestParam(required=true) String resToken,@RequestParam String pin_data,@RequestParam String pay_hwm,@RequestParam String day_hwm,
                                    @RequestParam String pf_hwm,@RequestParam String pf_day_hwm,Model model, HttpSession httpSession) {
        try {
            //todo  	支付账户修改
            // User user = (User) httpSession.getAttribute(Dict.LOGINUSER);
            //logger.debug(user.getTel());
            AjaxData ajaxData = getAjaxData();
            Map data = new HashMap();
            data.put("txn_id",headFormatter.getTxnMaping().get(Dict.TRS_MODIFYPAYFUNCONFIRM));
            data.put("chnl","155");
            data.put("accno","155111");
            data.put("pin_retry","3");
            data.put("systrace","155123");
            data.put("rc","155122");
            data.put("rc_detail","返回码解释:支付账户修改");
            data.put("acq_id","012345");
            data.put("org_code","12345");
            data.put("teller","code123");
            data.put("txn_date","2016-8-30");
            data.put("txn_time",new Date());
            ajaxData.setDataMap(data);
            model.addAttribute(CommonDict.RES,ajaxData);
        } catch (AccessRuntimeException e) {
            throw new AccessRuntimeException(e.getMessage(), e);
        } catch (Exception e) {
            e.printStackTrace();
            throw new AccessRuntimeException(AccessRuntimeExceptionDict.ERROR_MODIFYPAYFUNCONFIRM);
        }
    }

    /**
     * 支付账户详细情况查询请求
     * @param model
     * @param httpSession
     */
    @RequestMapping(value = Dict.TRS_PAYFUNDETAQRY, method = RequestMethod.GET)
    public void payFunDetaQry(Model model, HttpSession httpSession) {
        try {
            //todo  	支付账户详细情况查询
            // User user = (User) httpSession.getAttribute(Dict.LOGINUSER);
            //logger.debug(user.getTel());
            AjaxData ajaxData = getAjaxData();
            Map data = new HashMap();
            data.put("txn_id",headFormatter.getTxnMaping().get(Dict.TRS_PAYFUNDETAQRY));
            data.put("chnl","150");
            data.put("accno","150111");
            data.put("bal_amt","1200000");
            data.put("bal_amt3","120000");
            data.put("rc","155122");
            data.put("rc_detail","返回码解释:支付账户详细情况查询");
            data.put("acq_id","012345");
            data.put("org_code","12345");
            data.put("teller","code123");
            data.put("pin_data","12");
            data.put("pin_tag","123");
            data.put("pin_retry","1");
            data.put("pin_mode","1221");
            data.put("pf_hwm","121322");
            data.put("pf_day_hwm","12321");
            data.put("txn_date","2016-8-30");
            data.put("txn_time",new Date());
            data.put("open_date",new Date());
            data.put("cust_name","150150");
            data.put("mobile","182206853384");
            data.put("status","0000");
            data.put("acc_list","userlist");
            data.put("chnl","15000");
            data.put("memo","备注：支付账户详细情况查询");
            ajaxData.setDataMap(data);
            model.addAttribute(CommonDict.RES,ajaxData);
        } catch (AccessRuntimeException e) {
            throw new AccessRuntimeException(e.getMessage(), e);
        } catch (Exception e) {
            e.printStackTrace();
            throw new AccessRuntimeException(AccessRuntimeExceptionDict.ERROR_PAYFUNDETAQRY);
        }
    }

    @Override
    public void setServletContext(ServletContext servletContext) {
        this.servletContext = servletContext;
    }

}


